package com.inspinia.message.rpc.service;

import com.inspinia.message.rpc.api.NoticeService;
import redis.clients.jedis.JedisPubSub;

import javax.annotation.Resource;

/**
 * key过期的监听器
 * 参照：http://www.cnblogs.com/vianzhang/p/7756159.html
 */
public class KeyExpiredListener extends JedisPubSub {

    @Resource
    private NoticeService noticeService;

    @Override
    public void onPMessage(String pattern, String channel, String message) {

        if (message.startsWith(NoticeServiceImpl.CACHE_KEY_EX_NOTICE)) {
            String id = message.split(":")[1];
            noticeService.push(Long.valueOf(id));
        }
    }

}